var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var util = require('util');
var signServletAgent = require('./servers/getSignServletAgent.js');
var vCodeAgent = require('./servers/verficationCodeAgent.js');
var getNumServletAgent = require('./servers/getNumServletAgent.js');
var youtouAgent = require('./servers/youtuServletAgent.js');
var hengFengAgent = require('./servers/hengFengAgent.js');
var kexinBarbrecordAgent = require('./servers/kexinbadrecordAgent.js');
var kexinBrokenAgent = require('./servers/kexinBrokenAgent.js');
var dataAgent = require('./servers/getDateAgent.js');
var smsSeverAgent = require('./servers/sendSMSServletAgent.js');
var configAgent = require('./servers/getConfigAgent.js');

// 创建 application/x-www-form-urlencoded 编码解析
var urlencodedParser = bodyParser.urlencoded({
    extended: false
});

app.get('/', function(req, res) {
    res.send('Hello World');
});

app.get('/dist/faceDetect/faceDetect.html', function(req, res) {
    res.sendFile(__dirname + "/dist/faceDetect/faceDetect.html");
});
app.get('/dist/creditLoan/apply.html', function(req, res) {
    res.sendFile(__dirname + "/dist/creditLoan/apply.html");
});
app.get('/dist/creditLoan/webApply.html', function(req, res) {
    res.sendFile(__dirname + "/dist/creditLoan/webApply.html");
});

app.get('/dist/creditLoan/loanInquiry.html', function(req, res) {
    res.sendFile(__dirname + "/dist/creditLoan/loanInquiry.html");
});
app.get('/dist/creditLoan/promptBrowser.html', function(req, res) {
    res.sendFile(__dirname + "/dist/creditLoan/promptBrowser.html");
});
app.get('/dist/creditLoan/details.html', function(req, res) {
    res.sendFile(__dirname + "/dist/creditLoan/details.html");
});
app.get('/dist/creditLoan/query.html', function(req, res) {
    res.sendFile(__dirname + "/dist/creditLoan/query.html");
});
app.get('/dist/creditLoan/inquiry.html', function(req, res) {
    res.sendFile(__dirname + "/dist/creditLoan/inquiry.html");
});
app.get('/dist/creditLoan/question.html', function(req, res) {
    res.sendFile(__dirname + "/dist/creditLoan/question.html");
});
app.get('/dist/creditLoan/testCode.html', function(req, res) {
    res.sendFile(__dirname + "/dist/creditLoan/testCode.html");
});

app.get('/html/applyInstalment.html', function(req, res) {
    res.sendFile(__dirname + "/html/applyInstalment.html");
});
app.get('/dist/gateway/gatewayWeChat.html', function(req, res) {
    res.sendFile(__dirname + "/dist/gateway/gatewayWeChat.html");
});






app.get('/dist/js/libs/jquery-1.11.1.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/libs/jquery-1.11.1.min.js");
});
app.get('/dist/js/libs/jquery-3.0.0.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/libs/jquery-3.0.0.min.js");
});
app.get('/dist/js/libs/iscroll5.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/libs/iscroll5.js");
});


app.get('/dist/js/faceDetect/urlValue.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/urlValue.js");
});
app.get('/dist/js/libs/jquery.mobile-1.4.5.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/libs/jquery.mobile-1.4.5.min.js");
});
app.get('/dist/js/libs/iscroll5.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/libs/iscroll5.js");
});

app.get('/dist/js/faceDetect/common.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/common.js");
});
app.get('/dist/js/faceDetect/faceIndex.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/faceIndex.min.js");
});
app.get('/dist/js/creditLoan/common.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/creditLoan/common.js");
});
app.get('/dist/js/creditLoan/creditApply.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/creditLoan/creditApply.min.js");
});

app.get('/dist/js/creditLoan/creditwebApply.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/creditLoan/creditwebApply.min.js");
});
app.get('/dist/js/creditLoan/iscroll5.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/creditLoan/iscroll5.js");
});

app.get('/dist/js/creditLoan/loanInquiry.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/creditLoan/loanInquiry.min.js");
});
app.get('/dist/js/creditLoan/details.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/creditLoan/details.min.js");
});

app.get('/dist/js/creditLoan/urlValue.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/creditLoan/urlValue.js");
});
app.get('/dist/js/creditLoan/inquiry.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/creditLoan/inquiry.js");
});

app.get('/dist/js/gateway/gatewayIndex.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/gateway/gatewayIndex.min.js");
});
app.get('/dist/js/gateway/urlVal.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/gateway/urlVal.js");
});
 


app.get('/instalments/js/lfq/urlVar.js', function(req, res) {
    res.sendFile(__dirname + "/instalments/js/lfq/urlVar.js");
});
app.get('/js/lfq/zepto.min.js', function(req, res) {
    res.sendFile(__dirname + "/js/lfq/zepto.min.js");
});
app.get('/instalments/js/lfq/apply.min.js', function(req, res) {
    res.sendFile(__dirname + "/js/lfq/apply.min.js");
});

app.get('/js/lfq/common.min.js', function(req, res) {
    res.sendFile(__dirname + "/js/lfq/common.min.js");
});
app.get('/js/lfq/jquery-weui.min.js', function(req, res) {
    res.sendFile(__dirname + "/js/lfq/jquery-weui.min.js");
});



app.get('/dist/css/faceDetect/faceMain.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/faceDetect/faceMain.css");
});
app.get('/dist/css/test/fixedLayout.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/test/fixedLayout.css");
});
app.get('/dist/css/creditLoan/apply.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/creditLoan/apply.css");
});
app.get('/dist/css/creditLoan/query.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/creditLoan/query.css");
});
app.get('/css/applyInstalment2.css', function(req, res) {
    res.sendFile(__dirname + "/css/applyInstalment2.css");
});
app.get('/dist/css/gateway/gatewayIndex.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/gateway/gatewayIndex.css");
});




app.get('/dist/images/faceDetect/saomiao.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/faceDetect/saomiao.png");
});
app.get('/dist/images/faceDetect/lansebeijing_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/faceDetect/lansebeijing_icon.png");
});
app.get('/dist/images/faceDetect/demo.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/faceDetect/demo.png");
});
app.get('/dist/images/faceDetect/demo2_0.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/faceDetect/demo2_0.png");
});
app.get('/dist/images/faceDetect/demo3.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/faceDetect/demo3.png");
});
app.get('/dist/images/faceDetect/demo2_1.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/faceDetect/demo2_1.png");
});
app.get('/dist/images/faceDetect/demo2_2.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/faceDetect/demo2_2.png");
});
app.get('/dist/images/faceDetect/naixindengdai_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/faceDetect/naixindengdai_icon.png");
});
app.get('/dist/images/creditLoan/banner-2.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/banner-2.png");
});
app.get('/dist/images/creditLoan/xiaotongxinyongdai_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/xiaotongxinyongdai_icon.png");
});
app.get('/dist/images/creditLoan/underline.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/underline.png");
});
app.get('/dist/images/creditLoan/fanhui.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/fanhui.png");
});
app.get('/dist/images/creditLoan/dingdan_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/dingdan_icon.png");
});
app.get('/dist/images/creditLoan/loading.gif', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/loading.gif");
});
app.get('/dist/images/creditLoan/shenqingchenggong_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/shenqingchenggong_icon.png");
});
app.get('/dist/images/creditLoan/shibai_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/shibai_icon.png");
});
app.get('/dist/images/creditLoan/shuaxin_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/shuaxin_icon.png");
});
app.get('/dist/images/creditLoan/chenggong_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/chenggong_icon.png");
});
app.get('/dist/images/creditLoan/sb_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/sb_icon.png");
});
app.get('/dist/images/creditLoan/guanbi_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/guanbi_icon.png");
});
app.get('/dist/images/creditLoan/tianxiejiekuanjine_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/tianxiejiekuanjine_icon.png");
});
app.get('/dist/images/creditLoan/xiaotongxinyongdai_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/xiaotongxinyongdai_icon.png");
});
app.get('/dist/images/creditLoan/xuanzehuankuanfangshi_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/xuanzehuankuanfangshi_icon.png");
});
app.get('/dist/images/creditLoan/tianxiebenrenxinxi_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/tianxiebenrenxinxi_icon.png");
});
app.get('/dist/images/creditLoan/tiqianhuankuan_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan//tiqianhuankuan_icon.png");
});
app.get('/dist/images/creditLoan/tianxiexinyongkaxinxi.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/tianxiexinyongkaxinxi.png");
});
app.get('/dist/images/creditLoan/yanjing_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/yanjing_icon.png");
});
app.get('/dist/images/creditLoan/tianxieshoukuankahao_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/tianxieshoukuankahao_icon.png");
});
app.get('/dist/images/creditLoan/xinhuodong_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/xinhuodong_icon.png");
});






app.get('/dist/images/creditLoan/dianjiliaojie_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/dianjiliaojie_icon.png");
});
app.get('/dist/images/creditLoan/xuanzehuankuanqishu_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/xuanzehuankuanqishu_icon.png");
});
app.get('/dist/images/creditLoan/wozhidaola.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/wozhidaola.png");
});
app.get('/dist/images/creditLoan/daozhangshijian_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/daozhangshijian_icon.png");
});
app.get('/dist/images/creditLoan/huankuanfangshi_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/huankuanfangshi_icon.png");
});
app.get('/dist/images/creditLoan/jiekuanjine_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/jiekuanjine_icon.png");
});
app.get('/dist/images/creditLoan/shijian_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/shijian_icon.png");
});
app.get('/dist/images/creditLoan/shoukuankahao_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/shoukuankahao_icon.png");
});
app.get('/dist/images/creditLoan/tiaojian_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/tiaojian_icon.png");
});
app.get('/dist/images/creditLoan/tiqianhuankuan_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/tiqianhuankuan_icon.png");
});
app.get('/dist/images/creditLoan/tiaojian_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/tiaojian_icon.png");
});
app.get('/dist/images/creditLoan/tiqianhuankuan_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/tiqianhuankuan_icon.png");
});
app.get('/dist/images/creditLoan/shoukuankahao_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/shoukuankahao_icon.png");
});






app.get('/dist/images/creditLoan/yemianwufaxianshi_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/yemianwufaxianshi_icon.png");
});
app.get('/dist/images/creditLoan/tmup.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/creditLoan/tmup.png");
});




 


app.post('/liveDec/GetSignServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = signServletAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});

app.post('/liveDec/SMSSendServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = vCodeAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});
app.post('/liveDec/GetCheckNumServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = getNumServletAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});
app.post('/liveDec/YouTuDetectServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = youtouAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});
app.post('/liveDec/KexinBrokenServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = kexinBrokenAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});
app.post('/liveDec/KexinBadrecordServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = kexinBarbrecordAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});
app.post('/liveDec/HengFengServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = hengFengAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});
app.post('/FuLiBao/LFQCreateOrderServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = dataAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});

app.post('/FuLiBao/tltd/sms/send', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = dataAgent.getAgent({path:"/FuLiBao/tltd/sms/send"}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});
app.post('/LFQSendSMSServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = dataAgent.getAgent({path:"/LFQSendSMSServlet"}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});

app.post('/FuLiBao/LFQSendSMSServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = smsSeverAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});
app.post('/FuLiBao/LFQPlaceServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = configAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});



app.post('/payinstallment/payInstallmentInfoServlet', urlencodedParser, function(req, res) {
  res.writeHead(200,{'Content-Type':'text/html;charset=utf-8'});//设置response编码为utf-8
  console.log("-----取支付网关的分期信息-----");
  console.log(util.inspect(req.body));
  // 输出 JSON 格式
  var response = {
    "code": "0000",
    "msg": "",
    "data": {
      "orderId": "201702061602372528",
      "merName": "æµ‹è¯•æ±‡åˆ†æœŸ",
      "amount": "8000",
      "nper": "6",
      "unalter": "creditNo,creditName",
      "tradeDate": "2017-02-06 16:02:37",
      "returnUrl": "http://localhost:8080/allinpay-online/",
      "custName": "å¯å¯",
      "credCardno": "6259986239282080",
      "idno": "340603199402064797",
      "hpno": "17073547336",
      "cvv": "",
      "vaPerd": "",
      "simplPC": "0",
      "rateList": [{
        "nper": "3",
        "custRate": "12.26",
        "amtLowLimit": "600",
        "amtUplimit": "15000",
        "poundage": "326.94",
        "eachamount": "2993.60",
        "totalamount": "8980.80"
      }, {
        "nper": "6",
        "custRate": "0",
        "amtLowLimit": "1000",
        "amtUplimit": "20000",
        "poundage": "0.00",
        "eachamount": "1333.33",
        "totalamount": "8000.00"
      }, {
        "nper": "9",
        "custRate": "12",
        "amtLowLimit": "600",
        "amtUplimit": "20000",
        "poundage": "106.67",
        "eachamount": "995.55",
        "totalamount": "8960.00"
      }, {
        "nper": "10",
        "custRate": "9",
        "amtLowLimit": "600",
        "amtUplimit": "20000",
        "poundage": "72.00",
        "eachamount": "872.00",
        "totalamount": "8720.00"
      }, {
        "nper": "12",
        "custRate": "0",
        "amtLowLimit": "600",
        "amtUplimit": "25000",
        "poundage": "0.00",
        "eachamount": "666.66",
        "totalamount": "8000.00"
      }, {
        "nper": "18",
        "custRate": "0",
        "amtLowLimit": "600",
        "amtUplimit": "20000",
        "poundage": "0.00",
        "eachamount": "444.44",
        "totalamount": "8000.00"
      }, {
        "nper": "24",
        "custRate": "20",
        "amtLowLimit": "600",
        "amtUplimit": "20000",
        "poundage": "66.67",
        "eachamount": "400.00",
        "totalamount": "9600.00"
      }]
    }
  };

  var theAgent = dataAgent.getAgent({path: '/assetbm/payinstallment/stage/query'}, req.body);
  theAgent.on("databack", function(data) {
    console.log("datback...后台返回...");
    console.log('data: ' + data);
//    res.end(data);
  });
  theAgent.request();
  //  console.log(JSON.stringify(response));
    res.end(JSON.stringify(response));

});






var server = app.listen(9081, function() {

    var host = server.address().address;
    var port = server.address().port;

    console.log("应用实例，访问地址为 http://%s:%s", host, port)

});